﻿using System;
using System.Windows;
using Csla.Xaml;
using Accounting.Library;

namespace csla4Skeleton.UI.SL.TongHop.TH_SoChiTiet
{
    public partial class TH_SoChiTiet_ListViewModel : ViewModel<TH_SoChiTietList>
    {
        public event EventHandler LoadCompleted;
        public TH_SoChiTiet_ListViewModel(string mode)
        {
            BeginRefresh("GetTH_SoChiTietList", mode);

        }
        public TH_SoChiTiet_ListViewModel(string mode ,int HangHoaId , int DoiTuongTHCPId, string listTaiKhoan)
        {
            BeginRefresh("GetTH_SoChiTietList", mode + ";" + HangHoaId.ToString() + ";" + DoiTuongTHCPId.ToString() +";" + listTaiKhoan);

        }
        public TH_SoChiTiet_ListViewModel(int thang, int nam, string mode)
        {
            string value = thang.ToString() +"," +nam.ToString() + "," + mode;
            BeginRefresh("GetTH_SoChiTietList", value);

        }

        public void GetTH_SoChiTiet_ListViewModel(string mode)
        {
            BeginRefresh("GetTH_SoChiTietList", mode);
        }

        public static readonly DependencyProperty SelectedItemProperty =
          DependencyProperty.Register("SelectedItem", typeof(TH_SoChiTietInfo), typeof(TH_SoChiTiet_ListViewModel), null);
        public TH_SoChiTietInfo SelectedItem
        {
            get { return (TH_SoChiTietInfo)GetValue(SelectedItemProperty); }
            set { SetValue(SelectedItemProperty, value); }
        }

        protected override void OnRefreshed()
        {
            base.OnRefreshed();
            if (Model != null)
            {
                if (LoadCompleted != null)
                {
                    LoadCompleted(this, new EventArgs());
                }
            }
        }
        public void DeleteTH_SoChiTiet(object sender, ExecuteEventArgs e)
        {
            if (e.MethodParameter != null)
            {
                //cast OrderID parameter
                int Khoa = Int16.Parse(e.MethodParameter.ToString());
                this.IsBusy = true;
                Accounting.Library.TH_SoChiTiet.DeleteTH_SoChiTiet(Khoa, (o, ex) =>
                {
                    BeginRefresh("GetTH_SoChiTietList",BusinessConfiguration.Configuration.GridViewFetchMode);
                });
                this.IsBusy = false;
            }
        }	
    }
}
